'''
递归
'''
class Solution:
    def TreeDepth(self, root):
        # write code here
        if not root:
            return 0
        left = self.TreeDepth(root.left) + 1
        right = self.TreeDepth(root.right) + 1
        return max(left,right)
'''
非递归
层序遍历加一个counter计数，有几层就有多深
'''
# -*- coding:utf-8 -*-
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
class Solution:
    def TreeDepth(self, root):
        # write code here
        if not root:
            return 0
        depth=0
        node=[root]
        while node:
            nex=[]
            for node in node:
                if node.left:
                    nex.append(node.left)
                if node.right:
                    nex.append(node.right)
            node=nex
            depth=depth+1
        return depth